package com.tin.restfinder;

import java.util.ArrayList; 
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;


public class AppConfiguration {
	private ArrayList<String> tags;
	private ArrayList<Restaurant> list;
	private ArrayList<String> rest_names;
	private Date last_update;
	
	AppConfiguration()
	{
		tags = new ArrayList<String>();
		list = new ArrayList<Restaurant>();
		rest_names = new ArrayList<String>();
		last_update=new Date();
		last_update.setTime(0);
	}
	public ArrayList<String> getTags() {
		return tags;
	}

	public void setTags(ArrayList<String> tags) {
		this.tags = tags;
	}

	public ArrayList<Restaurant> getList() {
		return list;
	}

	public void setList(ArrayList<Restaurant> list) {
		this.list = list;
	}

	public ArrayList<String> getRest_names() {
		return rest_names;
	}

	public void setRest_names(ArrayList<String> rest_names) {
		this.rest_names = rest_names;
	}

	public Date getLast_update() {
		return last_update;
	}

	public void setLast_update(Date last_update) {
		this.last_update = last_update;
	}
	
	public void SynchronizeRestList()
	{
		SqlConnector.UpdateRestaurantList(list);
		SqlConnector.CheckIfRestListIsUptoDate(list);
		SqlConnector.SynchronizeLogo(list);
		SqlConnector.SynchronizeTags(list);
		SqlConnector.SynchronizeComments(list);
	    Date temp=new Date();
	    Data.conf.setLast_update(temp);
	}
	public void SynchronizeTags()
	{
		tags.clear();
		for(int i =0;i<list.size();i++)
			for(int l=0;l<list.get(i).getTags().size();l++)
				if(!list.get(i).getTags().get(l).equals(""))
					tags.add(list.get(i).getTags().get(l));
		tags = new ArrayList<String>(new HashSet<String>(tags)); // czyszczenie duplikatow
		
		Collections.sort(tags, new Comparator<String>() {
	        @Override
	        public int compare(String s1, String s2) {
	            return s1.compareToIgnoreCase(s2);
	        }
	    });
		
	}
	public void SynchronizeRestName()
	{
		rest_names.clear();
		for(int i =0;i<list.size();i++)
			rest_names.add(list.get(i).getName());
		 
		Collections.sort(rest_names, new Comparator<String>() {
		        @Override
		        public int compare(String s1, String s2) {
		            return s1.compareToIgnoreCase(s2);
		        }
		    });

	}
}

